package com.lzj.demo.exception;


import com.lzj.demo.design.common.ServerResult;
import com.lzj.demo.design.common.ServerResultCode;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 * @author A80405
 */
@RestControllerAdvice
public class GlobalException {
    private static final Logger log = LogManager.getLogger(GlobalException.class);

    /**
     * 运行时异常返回
     * @param e
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public ServerResult exceptionHandler(Exception e){
        log.error(e.getMessage(),e);
        return ServerResult.fail(ServerResultCode.RUN_ERROR);
    }
}
